package com.finance.controller;

import com.finance.config.Result;
import com.finance.model.entity.股票码表;
import com.finance.model.entity.股票记录;
import com.finance.model.request.股票码表Request;
import com.finance.model.request.股票记录Request;
import com.finance.service.impl.股票码表ServiceImpl;
import com.finance.service.impl.股票记录ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 邓天天
 * @date 2021/6/21 10:35
 */
@RestController
@RequestMapping("/股票")
public class 股票Controller {
    @Autowired
    股票码表ServiceImpl 对象_股票码表Service;

    @Autowired
    股票记录ServiceImpl 对象_股票记录Service;

    @PutMapping("/记录/save")
    public Result<String> save股票记录(@RequestBody List<股票记录Request> request) {
        List<股票记录> entityList = new ArrayList<>(request.size());
        for (var 对象_股票记录Request : request) {
            var entity = new 股票记录();
            BeanUtils.copyProperties(对象_股票记录Request, entity);
            entityList.add(entity);
        }
        if (对象_股票记录Service.saveBatch(entityList)) {
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping("/记录/listAll")
    public Result<List<股票记录>> list股票记录() {
        return Result.success(对象_股票记录Service.list());
    }

    @PutMapping("/码表/save")
    public Result<String> save股票码表(List<股票码表Request> request) {
        List<股票码表> entityList = new ArrayList<>(request.size());
        for (var 对象_股票码表Request : request) {
            var entity = new 股票码表();
            BeanUtils.copyProperties(对象_股票码表Request, entity);
            entityList.add(entity);
        }
        if (对象_股票码表Service.saveBatch(entityList)) {
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping("/码表/listAll")
    public Result<List<股票码表>> list股票码表() {
        return Result.success(对象_股票码表Service.list());
    }


}
